package gov.pbc.nn.uflo.el;

import java.util.Map;

import com.bstek.bdf2.core.context.ContextHolder;
import com.bstek.dorado.core.el.ContextVarsInitializer;
import com.bstek.uflo.client.service.ProcessClient;
import com.bstek.uflo.client.service.TaskClient;
import com.bstek.uflo.model.task.Task;

public class UfloContextVarsInitializer implements ContextVarsInitializer {

	@Override
	public void initializeContext(Map<String, Object> vars) throws Exception {
		ProcessVarsInitializer pvi = new ProcessVarsInitializer();
		vars.put("ProcessVar", pvi);
		vars.put("processVar", pvi);
		vars.put("task", new TaskVarsInitializer());
	}

	public static class ProcessVarsInitializer {

		public Object get(String varName, String piId) {
			ProcessClient pc = ContextHolder.getBean(ProcessClient.BEAN_ID);
			return pc.getProcessVariable(varName, Long.parseLong(piId));
		}
	}

	public static class TaskVarsInitializer {

		public Task get(String taskId) {
			TaskClient tc = ContextHolder.getBean(TaskClient.BEAN_ID);
			return tc.getTask(Long.parseLong(taskId));
		}
	}
}
